
const https = require('https');

// 云开发HTTP API配置
const config = {
  env: 'your-env-id', // 需要替换为实际的环境ID
  collection: 'plm_research_project',
  accessToken: '' // 需要填入访问令牌
};

// 构建请求选项
const options = {
  hostname: 'api.weixin.qq.com',
  path: `/tcb/databasequery?access_token=${config.accessToken}`,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  }
};

// 构建查询数据
const postData = JSON.stringify({
  env: config.env,
  query: `db.collection("${config.collection}").limit(100).get()`
});

// 发送请求
const req = https.request(options, (res) => {
  let data = '';

  res.on('data', (chunk) => {
    data += chunk;
  });

  res.on('end', () => {
    console.log('查询结果:');
    console.log(JSON.parse(data));
  });
});

req.on('error', (error) => {
  console.error('查询失败:', error);
});

// 写入数据并结束请求
req.write(postData);
req.end();